home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / mailhand / metamail.z / metamail / bin / showexternal < prev    next >
Encoding:
Text File  |  1992-04-03  |  4.9 KB  |  195 lines

  1. #!/bin/csh -f
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. if ($#argv <3) then
  15.     echo "Usage: showexternal body-file access-type name [site [directory [mode]]]"
  16.     exit -1
  17. endif
  18. set bodyfile=$1
  19. set atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  20. set name=$3
  21. if ($#argv > 3) then
  22.     set site=$4
  23. else 
  24.     set site=""
  25. endif
  26. if ($#argv > 4) then
  27.     set dir=$5
  28. else
  29.     set dir=""
  30. endif
  31. if ($#argv > 5) then
  32.     set mode=$6
  33. else
  34.     set mode=""
  35. endif
  36.  
  37. set ctype=`grep -i content-type: $bodyfile | sed -e 's/............: //'`
  38. set cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  39. set username=""
  40. set pass=""
  41. set TMPDIR=/tmp/XXXternal.$$
  42. mkdir $TMPDIR
  43. cd $TMPDIR
  44. set NEWNAME="mm.ext.$$"
  45. set NEEDSCONFIRMATION=1
  46. switch ($atype)
  47.     case anon-ftp:
  48.     echo "This mail message contains a POINTER (reference) to data that is "
  49.     echo not included in the message itself.  Rather, the data can be retrieved 
  50.     echo automatically using  anonymous FTP to a site on the network.
  51.     breaksw
  52.     case ftp:
  53.     echo "This mail message contains a POINTER (reference) to data that is "
  54.     echo not included in the message itself.  Rather, the data can be retrieved 
  55.     echo automatically using  the FTP protocol to a site on the network.
  56.     breaksw
  57.     case mail-server:  
  58.     cat > /tmp/ext.junk.$$ <<!
  59. This mail message contains a POINTER (reference) to data that is 
  60. not included in the message itself.  Rather, the data can be retrieved 
  61. by sending a special mail message to a mail server on the network.
  62. However, doing this automatically is slightly dangerous, because  someone
  63. might be using this mechanism to cause YOU to send obnoxious mail.
  64. For that reason, the mail message that WOULD be sent is being shown to you
  65. first for your approval.
  66.  
  67. This is the message that will be sent if you choose to go ahead and
  68. retreive the external data:
  69.  
  70. To: ${name}@${site}:
  71. Subject: Automated Mail Server Request
  72.  
  73. !
  74.     cat $bodyfile >> /tmp/ext.junk.$$
  75.     more /tmp/ext.junk.$$
  76.     rm /tmp/ext.junk.$$
  77.     breaksw
  78.     default:
  79.     # IGNORE ALL THE OTHERS -- AUTOMATIC FOR LOCAL-FILE, AFS.
  80.     set NEEDSCONFIRMATION=0
  81. endsw
  82.  
  83. if ($NEEDSCONFIRMATION) then
  84.     echo ""
  85.     echo -n "Do you want to proceed with retrieving the external data [y] ? "
  86.     set ANS=$<
  87.     if ("$ANS" =~ n* ||  "$ANS" =~ N* ) exit 0
  88. endif
  89.  
  90. switch ($atype)
  91.     case anon-ftp:
  92.     set username=anonymous
  93.     set pass=`whoami`@`hostname`
  94.     # DROP THROUGH
  95.     case ftp:
  96.     if ("$site" == "") then
  97.         echo -n "Site for ftp access: "
  98.         set site=$<
  99.     endif
  100.     if ("$username" == "") then
  101.         echo -n "User name at site ${site}: "
  102.         set username=$<
  103.     endif
  104.     if ("$pass" == "") then
  105.         echo -n "Password for user $username at site ${site}: "
  106.         stty -echo
  107.         set pass=$<
  108.         stty echo
  109.         echo ""
  110.     endif
  111.     if ("$dir" == "") then
  112.         set DIRCMD=""
  113.     else
  114.         set DIRCMD="cd $dir"
  115.     endif
  116.     if ("$mode" == "") then
  117.         set MODECMD=""
  118.     else
  119.         set MODECMD="type $mode"
  120.     endif
  121.     echo OBTAINING MESSAGE BODY USING FTP
  122.     echo SITE: $site USER $username
  123.     ftp -n <<!
  124. open $site
  125. user $username $pass
  126. $DIRCMD
  127. $MODECMD
  128. get $name $NEWNAME
  129. quit
  130. !
  131.     if (! -e $NEWNAME) then
  132.         echo FTP failed.
  133.         exit -1
  134.     endif
  135.     breaksw
  136.     case afs:
  137.     case local-file:
  138.     if (! -e $name) then
  139.         echo local file not found
  140.         exit -1
  141.     endif
  142.         set NEWNAME=$name
  143.     echo GETTING BODY FROM FILE NAMED: $NEWNAME
  144.     breaksw
  145.     case mail-server:  # A very special case
  146.     if ("$bodyfile" == "") then
  147.         echo mail-server access-type requires a body file
  148.         exit -1
  149.     endif
  150.     echo Subject: Automated Mail Server Request > $NEWNAME
  151.     echo To: ${name}@${site} >> $NEWNAME
  152.     echo "" >> $NEWNAME
  153.     cat $bodyfile >> $NEWNAME
  154.     /usr/lib/sendmail -t  < $NEWNAME
  155.     if ($status) then
  156.         echo sendmail failed
  157.         rm -rf $TMPDIR
  158.         exit -1
  159.     endif
  160.     rm -rf $TMPDIR
  161.     echo Your $ctype data has been requested from a mail server.
  162.     exit 0
  163.     default:
  164.     echo UNRECOGNIZED ACCESS-TYPE
  165.     exit -1
  166. endsw
  167. if ($cenc == base64) then
  168.     mmencode -u -b < $NEWNAME > OUT
  169.     mv OUT $NEWNAME
  170. else if ($cenc == quoted-printable) then
  171.     mmencode -u -q < $NEWNAME > OUT
  172.     mv OUT $NEWNAME
  173. endif
  174.  
  175. metamail -b -c $ctype $NEWNAME
  176.  
  177. if ($status) then
  178.     echo metamail failed
  179.     rm -rf $TMPDIR
  180.     exit -1
  181. endif
  182.  
  183. if ($NEWNAME != $name) then
  184.     echo ""
  185.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  186.     echo "Do you want to delete it?"
  187.     rm -i $NEWNAME
  188. endif
  189. if (! -e ${TMPDIR}/${NEWNAME}) then
  190.     rmdir $TMPDIR
  191. endif
  192. exit 0
  193.